package com.awesome.kotlindemo.function.thread

import android.os.Bundle
import android.os.PersistableBundle
import androidx.appcompat.app.AppCompatActivity
import com.awesome.common.util.log.ShowLogUtil
import com.awesome.kotlindemo.R
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 * Author: zhangjingfang
 * Email:zhangjingfang@jeejio.com
 * Date: 2021/11/25
 * Description:携程
 */
class ThreadActivity:AppCompatActivity () {
    override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
        super.onCreate(savedInstanceState, persistentState)
        setContentView(R.layout.activity_thread)
        // 携程
        GlobalScope.launch(Dispatchers.Main) {
            val a = withContext(Dispatchers.IO) {
                ShowLogUtil.info("1(Thread.currentThread().name="+Thread.currentThread().name)
            }
            ShowLogUtil.info("a=$a")
            ShowLogUtil.info("2(Thread.currentThread().name="+Thread.currentThread().name)
            launch(Dispatchers.IO) {
                ShowLogUtil.info("3(Thread.currentThread().name="+Thread.currentThread().name)
            }
        }
    }
}